<template>

  <div class="search">
    <el-input size="small" style="width: 400px" placeholder="请输入搜索内容" @input="(val) => { handleInput(val) }" v-model="searchValue" @keyup.enter.native="searchEnterFun">
      <!-- <i slot="suffix" class="el-icon-search" @click="search"></i> -->
      <!-- <div slot="prepend" class="Select">
        <el-select v-model="value" placeholder="请选择" @change="change">
          <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </div> -->
      <!-- <div slot="append" @click="search">
        <el-button icon="el-icon-search">搜索</el-button>
      </div> -->
      <!-- <el-button class="search_good_btn" slot="append" @click="searchGood()">搜商品</el-button> -->
    </el-input>
    <div class="search_good_btn" @click="searchGood()">搜商品</div>
    <div class="btn" @click="searchShop()" v-show="showSearchShop">搜店铺</div>
    <!-- <div class="qrCode" v-show="showQrCode"></div> -->
  </div>
</template>

<script>
  export default {
    props: {
      showSearchShop: {
        type: Boolean,
        default: true
      },
      showQrCode: {
        type: Boolean,
        default: true
      },
      searchContent: {
        type: String,
        default: ''
      },
    },
    data() {
      return {
        searchValue: "",
        options: [{
          value: '1',
          label: '商品'
        }, {
          value: '2',
          label: '店铺'
        }],
        value: '1',
        placeholder: '请输入商品'
      };
    },
    methods: {
      handleInput(val) {
        this.$emit('updateSearchContent', val)
      },
      change(e) {
        this.value = e;
      },
      // 回车搜索
      searchEnterFun: function(e) {
        var keyCode = window.event ? e.keyCode : e.which;
        // console.log('回车搜索',keyCode,e,this.searchValue);
        if (keyCode == 13 && this.searchValue) {
          this.search()
        }
      },
      search() {
        if (this.searchValue == '') {
          return
        }
        // value ==1 商品搜索  value==2 店铺搜索
        if (this.value == 1) {
          this.$router.push({
            path: "/front-goodList",
            query: {
              name$lk: this.searchValue,
              t: new Date().getTime()
            },
          });
        } else {
          this.$router.push({
            path: "/front-shopList",
            query: {
              name$lk: this.searchValue,
              t: new Date().getTime()
            },
          });
        }
      },
      searchGood() {
      	this.$router.push({
      		path: "/front-goodList",
      		query: {
      			name$lk: this.searchValue,
      			t: new Date().getTime()
      		},
      	});
      },
      searchShop() {
        if (this.searchValue == '') {
          return
        }
      	this.$router.push({
      		path: "/front-shopList",
      		query: {
      			name$lk: this.searchValue,
      			t: new Date().getTime()
      		},
      	});
      },
    },
    created() {
      this.searchValue = this.searchContent
    },
  };
</script>
<style>
  .search .el-input-group {
    flex: 1;
    width: auto;
  }
  .search .el-input--medium .el-input__inner {
    height: 44px;
    line-height: 44px;
    /* border: 1px solid #0f83c0 !important; */
    background-color: #FFFFFF;
    /* width: 230px; */
  }

  .el-input-group__append {
    background-color: #0F83C0;
    border: 1px solid #0f83c0 !important;
    color: #FFFFFF;
  }
  .search .el-icon-search:before {
    font-size: 18px;
    color: #FFFFFF;
  }
  .search .el-input--medium .el-input__inner::placeholder {
    color: #b3b3b3;
  }
  .search .el-icon-search{
  }

  /* .search .el-input-group__append:hover {
		opacity: 0.8;
	}
	.search .el-input-group__append {
		width: 108px;
		height: 44px;
		background: #965f29;
		border: 1px solid #965f29;
		border-radius: 0;
		text-align: center;
		color: #fff;
		cursor: pointer;
	} */
  .Select .el-input--medium .el-input__inner {
    height: 44px;
    line-height: 44px;
    width: 70px;
  }

  .Select.el-input-group__append,
  .el-input-group__prepend {
    background-color: #FFFFFF;
  }

  .Select .el-input__inner {
    padding: 0 10px;
  }
  .Select .el-input {
    width: 240%;
  }
  .hover:hover {
    color: #0f83c0;
  }
</style>
<style lang="scss" scoped>
  .search {
    display: flex;
    align-items: center;

    .search_good_btn {
      margin-left: 20px;
      width: 84px;
      height: 32px;
      line-height: 32px; 
      cursor: pointer;
      text-align: center;
      border-radius: 5px;
      color: white;
      background-color: rgba(14, 131, 192, 1);
      border-color: rgba(14, 131, 192, 1);
      // background-color: rgba(133, 0, 0, 1);
;
    }

    .btn {
      margin-left: 20px;
      width: 84px;
      height: 32px;
      line-height: 32px;
      background-color: rgba(43, 164, 74, 1);;
      // background: rgba(255, 159, 15, 1);
      color: #fff;
      cursor: pointer;
      text-align: center;
      border-radius: 5px;

      &:hover {
        opacity: 0.8;
      }
    }

    // .qrCode {
    // 	margin-left: 48px;
    // 	width: 85px;
    // 	height: 85px;
    // 	position: relative;
    // 	background: url(../../../assets/front-img/qrCode.png) center center no-repeat;
    // 	background-size: contain;

    // 	&::after {
    // 		content: "APP下载";
    // 		position: absolute;
    // 		text-align: center;
    // 		width: 100%;
    // 		top: 95px;
    // 		color: #965f29;
    // 	}
    // }
  }
</style>
